
package com.scalar.chiptrack.events;

import java.io.Serializable;


/**
 * Base Event Class
 * 
 * @author Balaram Putta
 */
public abstract class SSEvent implements Serializable
{
    protected SSEventName pEventName = null;
    protected SSEventType pEventType = null; 
    protected String pUserId = null;
    protected SSEventContext pEventContext = null;
    protected boolean eventInitiated = false;
    protected long pCreatedTimeStamp = -1L;
    

    public SSEvent( SSEventName name,
    				SSEventType type,
                    String userId,
                    SSEventContext context,
                    boolean initEvent )
    {
        pEventName = name;
        pEventType = type;

        pUserId = userId;
        pEventContext = context;

        if( initEvent )
        {
            pCreatedTimeStamp = System.currentTimeMillis();
            eventInitiated = true;
        }
    }


    /**
     * Detailed description of the event
     *
     * The idea is to construct XML encoded data and display it based on a style sheet
     * For now we will construct HTML content and display it directly
     * This method MUST be implemented by sub classes to explain the
     * event in detail.
     *
     */
    public abstract String getEventInfo();


    /**
     * Explicity initiates the event
     * No effect: if the event is already initiated
     */
    public void init()
    {
        if( eventInitiated == false )
        {
            pCreatedTimeStamp = System.currentTimeMillis();
        }
    }

    /**
     * Returns event created time stamp in Millis
     */
    public long getTimestamp()
    {
        return pCreatedTimeStamp;
    }

    /**
     * Specific event type under this event category
     */
    public SSEventType getType()
    {
        return pEventType;
    }

    /**
     * Event name 
     */
    public SSEventName getName()
    {
        return pEventName;
    }

    
    /**
     * object id of the source object - undergoing this change
     */
    public SSEventContext getContext()
    {
        return pEventContext;
    }

    /**
     * String representation of this event
     */
    public String toString()
    {
        return "{ Event Type: " + pEventName + ", Created On: " + new java.util.Date( pCreatedTimeStamp ) + " }";
    }


    /**
     * return the userid - responsible for this event
     */
    public String getUserId()
    {
        return pUserId;
    }

}

